import { sendServer } from '../request/common.js'
//获取商品分类
export const getGoodsType=()=>{
  return new Promise((resolve,reject)=>{
      let params={};
      params.url="goods/getGoodsType";
      sendServer(params,(commRes)=>{
          if(commRes.code==100){
              resolve(commRes)
          }
          reject(false); // 失败回调
          return false;
      })

  })
}

export const getGoodsList=()=>{
  return new Promise((resolve,reject)=>{
      let params={},send={}
      params.url='goods/list';
      sendServer(params,(commRes)=>{
          if(commRes.code==100){
              resolve(commRes)
          }
          reject(false); // 失败回调
          return false;
      })
  })
}

export const getAddList=()=>{
  return new Promise((resolve,reject)=>{
      let params={},send={}
      send.userId=wx.getStorageSync('userInfo').id
      params.send=send;
      params.url='address/showAddress';
      sendServer(params,(commRes)=>{
          if(commRes.code==100){
              resolve(commRes)
          }
          reject(false); // 失败回调
          return false;
      })
  })
}
//更新商品的数量
export const updateCart=(id,quantity)=>{
    return new Promise((resolve,reject)=>{
        let params={},send={}
        send.id=id;
        send.quantity=quantity;
        params.send=send;
        params.url='cart/updateCart';
        sendServer(params,(commRes)=>{
            if(commRes.code==100){
                resolve(commRes)
            }
            reject(false); // 失败回调
            return false;
        })

    })
}

module.exports={
  getGoodsType:getGoodsType,
  getGoodsList:getGoodsList,
  getAddList:getAddList,
  updateCart:updateCart,
}